{extend name="common@admin_base" /}

{block name="body"}
<form method="post" class="layui-form" lay-filter="menu_form">
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" name="name">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单路径</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" name="url">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级目录</label>
        <div class="layui-input-block">
            <select name="pid" lay-verify="required">
                <option value="">请选择</option>
                <option value="0">根目录</option>
                {volist name="pmenus" id="pmenu"}
                <option value="{$pmenu.id}" >{$pmenu.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单类型</label>
        <div class="layui-input-block">
            <select class="layui-input" name="type">
                <option value="1">管理菜单</option>
                <option value="2">前端菜单</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单状态</label>
        <div class="layui-input-block">
            <select class="layui-input" name="flag">
                <option value="10">不显示</option>
                <option value="20">显示置灰</option>
                <option value="30">显示标新</option>
                <option value="99">正常显示</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn" id="submit" lay-submit="" lay-filter="menu_form" type="submit" value="立即提交"/>
        </div>
    </div>
</form>
{/block}


{block name="head_extends"}
<script type="application/javascript">
    layui.use(['jquery', 'form'], function(){
        var $ = layui.jquery;
        var form = layui.form;

        form.on('submit(menu_form)',function (data) {
            console.log(data.field);
            $.ajax({
                url:'{$_form.admin_menu_save}'
                ,data:data.field
                ,method:'post'
                ,success:function (data) {
                    console.log(data);
                    if (typeof data == 'string'){
                        data = JSON.parse(data);
                    }
                    parent.layer.alert(data.info);
                    if (data.msg == 1){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}